import java.util.Scanner;
import java.util.Stack;

/**
 * Author: 王俊超
 * Time: 2016-05-07 08:13
 * CSDN: http://blog.csdn.net/derrantcm
 * Github: https://github.com/Wang-Jun-Chao
 * Declaration: All Rights Reserved !!!
 */
public class Main {
    public static void main(String[] args) {
        //创建链表
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        ListNode node6 = new ListNode(6);
        ListNode node7 = new ListNode(7);

        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        node5.next = node6;
        node6.next = node7;
        node7.next = null;

        printList(node1);
    }

    /**
     * 将链表中的每个节点存入栈中，根据栈后进先出的特点打印结果
     * @param head
     */
    public static  void printList(ListNode head){
       if(head == null){
           return;
       }
       Stack<Integer> stack = new Stack();
       while (head!=null){
           stack.push(head.value);
           head = head.next;
       }
       System.out.println("======倒叙输出链表========");
       while (!stack.isEmpty()){
           System.out.print(stack.pop()+" ");
       }
    }
    static class ListNode{
        int value;
        ListNode next;

        public ListNode(int value) {
            this.value = value;
        }
    }
}
